<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.css" rel="stylesheet" media="screen">
    <link href=".${pageContext.request.contextPath}/static/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery.min.js" charset="UTF-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/bootstrap-datetimepicker.js" charset="UTF-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
    <!-- 新 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap.css">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    String goodId = request.getParameter("updateGoodId");
    String categoryId = request.getParameter("updateCategoryId");
    String goodName = request.getParameter("updateGoodName");
    String price = request.getParameter("updateGoodPrice");
    String stock = request.getParameter("updateGoodStock");
%>
<div style="padding:5px; margin:0px;">
    <ul class="breadcrumb" style="  margin:0px; ">
        <li>
            <a href="#">商品管理</a>
        </li>
        <li>修改商品</li>
    </ul>
</div>
<form action="${pageContext.request.contextPath}/goods?method=update" method="post" class="form-horizontal">
    <div class="row">
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-3 control-label">商品编号</label>
                <div class="col-sm-9">
                    <input type="text" name="goodsId" class="form-control input-sm" readonly="readonly" value="<%=goodId%>"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品名称</label>
                <div class="col-sm-9">
                    <input type="text" name="goodsName" class="form-control input-sm" value="<%=goodName%>"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品类型</label>
                <div class="col-sm-4">
                    <select id="category" name="categoryId" class="form-control">
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品价格</label>
                <div class="col-sm-9">
                    <input type="text" name="goodsPrice" class="form-control input-sm" value="<%=price%>"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品库存</label>
                <div class="col-sm-9">
                    <input type="text" name="goodsStock" class="form-control input-sm" value="<%=stock%>"/>
                </div>
            </div>


        </div>
    </div>
    <!--结束 -->
    <div class="row">
        <div class="col-sm-3 col-sm-offset-2">
            <input  type="submit" class="btn btn-success" value="提交"/>
            <a class="btn btn-warning" href="${pageContext.request.contextPath}/goods?method=list">返回列表</a>
        </div>
    </div>
</form>

<script type="text/javascript">
    $(function(){
        $("#category").append("<option>--请选择商品类型--</option>");
        // Ajax获取商品类型信息，再通过DOM编程设置select
        $.post("${pageContext.request.contextPath}/category?method=findAllCategory",{},function(data){
            for(var i=0;i<data.length;i++){
                if(data[i].categoryId==<%=categoryId%>){
                    $("#category").append("<option selected='selected' value="+data[i].categoryId+">"+data[i].categoryName+"</option>");
                }else{
                    $("#category").append("<option value="+data[i].categoryId+">"+data[i].categoryName+"</option>");
                }
            }
        },"json");//指定返回类型为json
    });
</script>
</body>

</html>
